﻿/******************************************************************
 *Company: http://www.xiaomutech.com/
 *fileName : %{Cpp:License:FileName} --- %{Cpp:License:ClassName}
 *Auth       : Niyh  (QQ:393320854)
 *Create    : 2021-11-12
 *Description   :
 *Histroy:
 *<Auth>    <Date>        <Ver>        <Content>
 *         2021/11/12/11/12
 *******************************************************************/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qserialshell.h"

#include <QDebug>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_actionopen_com_triggered()
{
    bool bOk = ui->serialShell->open("COM4");
    ui->statusbar->showMessage(QString("[%1] 打开%2").arg("COM4").arg(bOk ? "成功" : "失败"));
}

void MainWindow::on_actionnew_com_triggered()
{
    ui->tabWidget->addTab(new QSerialShell(this), QString("串口助手[%1]").arg(ui->tabWidget->count()));
}

void MainWindow::on_actionabout_qt_triggered()
{
    QMessageBox::aboutQt(this);
}

void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
    if (ui->tabWidget->count() == 1) {
        ui->statusbar->showMessage(QString("最后一个不准删除！~"));
        return;
    }

    QSerialShell *widget = (QSerialShell *)ui->tabWidget->widget(index);
    if (NULL != widget) {
        delete widget;
        widget = NULL;
    }
}
